﻿using MultiThread.泛型.Impl;
using MultiThread.泛型.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace MultiThread
{
    
    class Program
    {

        private delegate void GetString();
        private delegate void Operator();
        private delegate void Operator1();
        private delegate void Operator2();
        private delegate void Lamda0();
        private delegate void Lamda1(string str);
        private delegate void Lamda2(string str,string str2);
        public static void Main(string[] args)
        {
            #region ThreadPool 用法
            //TreadPoolOperator.CreateMultiThread();
            //Console.ReadLine();
            #endregion
            #region 变量是类或结构中的字段，如果没有显式初始化，创建这些变量时，其值就默认是0(类和结构在后面讨论)。 方法的局部变量必须在代码中显式初始化，之后才能在语句中使用它们的值。
            //int i;
            //Console.WriteLine(i);
            #endregion
            //C++的char表示一个8位字符，而C#的char包含16位。其部分原因是不允许在char类型与8位byte类型之间进行隐式转换。
            //C#有15个预定义类型，其中13个是值类型，2个是引用类型(string和object)。
            #region check与unchecked用法
            //unchecked
            //{
            //    byte b = 255;
            //    b += 2;
            //    Console.WriteLine(b);
            //}
            //try
            //{
            //    checked
            //    {
            //        byte c = 255;
            //        c++;
            //        Console.WriteLine(c);
            //    }
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.GetType().Name + "\t" + e.Message);
            //}
            #endregion
            #region delegate用法
            //GetString test = () => Program.ConsoleString();//GetString test = Program.ConsoleString;<=>GetString test = new Delegate(Program.ConsoleString);
            //test();
            #endregion
            #region 多播委托
            //Operator operat = Program.Method1;
            //operat += Program.Method2;
            //operat();
            //operat -= Program.Method1;
            //operat();
            #endregion
            #region 匿名函数
            //Operator operat = delegate()
            //{
            //    Console.WriteLine("A method with no name");
            //};
            //operat();
            #endregion
            #region Lamda 与 委托
            //string s1="Lamda1";
            //string s2 = "Lamda2";
            //Lamda0 lamda0 = () => Console.WriteLine("there is no parameter");
            //Lamda1 lamda1 = o => Console.WriteLine("there is an parameter.it's {0}", o);
            //Lamda2 lamda2 = (a,b) => TestLamda(a,b);
            //lamda0();
            //lamda1(s1);
            //lamda2(s1, s2);
            #endregion
            #region 泛型类 T实例化后才能确定Class的类型 才能调用静态成员。
            //Console.WriteLine(TClass<int>.str); 
            #endregion
            #region partial:为类添加Extend方法。 可以写多个partial类
            testExtendMethod test = new testExtendMethod();
            test.GetPartialName();
            test.GetName();
            #endregion
            #region test default
            //ITestClass<string> testReferenceType = new TestClass<string>();
            //ITestClass<int> testValueType = new TestClass<int>();
            //Console.WriteLine(testReferenceType.GetValue());
            //Console.WriteLine(testValueType.GetValue());
            #endregion
            #region 泛型
            //Console.WriteLine(TestClass<int>.Name); 
            #region Array.sort

            #endregion
            #endregion
        }
        #region 不能根据返回值来确定函数，只能是函数名和参数。 
        //public static void Test()
        //{
        //    Console.WriteLine("Return Void");
        //}
        //public static int Test()
        //{
        //    return 0;
        //}
        #endregion
        public static void ConsoleString()
        {
            Console.WriteLine("Delegate");
        }
        public static void Method1()
        {
            Console.WriteLine("Method1");
        }
        public static void Method2()
        {
            Console.WriteLine("Method2");
        }
        public static void TestLamda(string str,string str2)
        {
            Console.WriteLine("test Lamda  by  a method with a paramter");
            Console.WriteLine(str+str2);
        }
    }
    public class ABase
    {
        public string str = "string";
        public virtual  void Output()
        {
            Console.WriteLine("BaseClass");
        }
    }
    public class A : ABase
    {   //new 显示隐藏基类
        public new void Output()
        {
            Console.WriteLine("AClass");
        }
    }

    public class TClass<T>
    {
        public static string str 
        {
            get { return "Test T Class"; }
        }
    }
    public partial class testExtendMethod
    {
        public string GetName()
        {
            return "Name";
        }
        
    }
    
    public partial class testExtendMethod
    {
        public string GetPartialName()
        {
            return "PartialName";
        }
    }
   
 }
